#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
{
	char buff[512]={0};

	snprintf(buff,512,"this is a simple test for snprintf.\n");
	printf("strlen(a long buff) = %d\n", strlen(buff));
	snprintf(buff,512,"a overlap test.\n");
	printf("strlen(a shorter buff) = %d\n", strlen(buff));

	printf("atoi(\"1;\") = %d\n", atoi("1;"));

	sscanf("\tNetransProfile\t\n","\t%[^\t/\n]", buff);
	printf("buff : %s\n", buff);

	/** snprintf */
	char tlist_1[1024]={0};
	char *tlist_2 = malloc(1024);
	char fname[7][8] = {"a1","b1","c1","d1","e1","f1","g1"};
	int i = 0, len_1,len_2 = 0;

	len_1 = snprintf(tlist_1,1024,"%s;",fname[0]);
	len_2 = snprintf(tlist_2,1024,"%s;",fname[0]);

	for(i=1;i<7;i++)
	{
		len_1 = snprintf(tlist_1,1024,"%s%s;",tlist_1,fname[i]);
		len_2 = sprintf(tlist_2,"%s%s;",tlist_2,fname[i]);
	}

	printf("tlist_1: %s\n",tlist_1);
	printf("tlist_2: %s\n",tlist_2);
	
	if(tlist_2) free(tlist_2);

	char tlist_3[10] = {0};
	int len_3 = 0;

	len_3 = snprintf(tlist_3,10,"this is a overflow test!\n");
	printf("len_3 = %d,tlist_3 = %s\n",len_3,tlist_3);

	return 0;
}


